<template>
    <div class="container">
        <mt-header  title="订单详情">
            <router-link to="" slot="left">
                <mt-button icon="back" @click.native="$router.back(-1)">返回</mt-button>
            </router-link>
        </mt-header>
        <div class="order-page">
            <div class="address-div" @click="showAddr">
                <div class="address-default" v-if="defaultAddr">
                    <div>订单配送至</div>
                    <div class="address-info">
                        <h2 class="show-one-line">{{ defaultAddr.diqu }} {{ defaultAddr.dizhi }}</h2>
                        <div class="address-arrow"> 重新选择 ></div>
                    </div>
                    <div>
                        <span>{{defaultAddr.name}}</span>
                        <span>{{ defaultAddr.tel }}</span>
                    </div>
                </div>
                <div class="address-none" v-else>
                    <div class="address-info">
                        <h2>请先选择收货地址</h2>
                        <div class="address-arrow"> ></div>
                    </div>
                </div>

            </div>
            <!--<div class="userinfo-form">
                <div class="section ">
                    <span>姓名</span>
                    <input placeholder="请输入真实姓名" name="username"/>
                </div>
                <div class="section ">
                    <span>身份证号</span>
                    <input type="text" placeholder="请输入身份证号" name="idcard"/>
                </div>
                <div class="section ">
                    <span>短信验证码</span>
                    <input type="number" placeholder="请输入短信验证码" name="phoneCode"/>
                </div>

            </div>-->
            <div class="product-info">
                <div class="project">
                    <img class="project-cover" v-bind:src="dataInfo.cover" alt="">
                    <div class="project-info">
                        <p class="project-name show-two-line">{{dataInfo.name}}</p>
                        <div class="project-detail">
                            <span>数量：1</span>
                            <span>¥ 0</span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="footer-info">
                <span>合计：0 元</span>
                <button class="btn project-btn" @click="submit">提交</button>
            </div>
        </div>

    </div>
</template>

<script>
    export default {
        name: "ProductSubmit",
        props: {
            choosedId:{
                type:Number,
                default:0
            }
        },
        data() {
            return {
                options: {
                    id: 0
                },
                dataInfo: {},
                defaultAddr: null,
                uid: 0,
            }
        },
        mounted() {
            this.options.id = this.$route.params.id
            this.uid = this.$store.getters.getUserInfo.uid
            this.getData()
            this.getAddress()
        },
        methods: {
            getData() {
                this.$axios( {
                    method: 'post',
                    url: 'Index/shangpin',
                    data: {
                        cid: this.options.id,
                    }
                } ).then( this.setData ).catch( error => {

                } );
            },
            setData( result ) {
                this.dataInfo = result.data
                this.dataInfo.cover = result.data.tupian[0]
            },
            submit() {
                const _this = this
                if (!this.defaultAddr || !this.defaultAddr.id) {
                    this.$msgbox.alert( '请先选择收件地址', '提示' )
                    return false
                }
                if (!this.uid) {
                    this.$msgbox.alert( '请先登录', '提示' ).then( action => {
                        _this.$router.push( {
                            path: '/mine',
                        } )
                    } );
                    return false
                }

                this.$axios( {
                    method: 'post',
                    url: 'Index/qiang_fmoren',
                    data: {
                        cid: this.options.id,
                        uid: this.uid,
                        dizhiid: this.defaultAddr.id,
                        cname: this.dataInfo.name
                    },
                } ).then( res => {
                    this.$msgbox.alert( '恭喜您，抢购成功', '抢购成功' ).then( action => {
                        _this.$router.go( -1 )
                    } )
                } ).catch( error => {
                    this.$msgbox.alert( error.msg, '出错了' )
                } );
            },
            getAddress() {
                if(!this.choosedId) {
                    this.$axios( {
                        method: 'post',
                        url: 'Index/dizhiqiang',
                        data: {
                            uid: this.uid
                        }
                    } ).then( res => {
                        this.defaultAddr = res.data
                    } ).catch( error => {

                    } );
                }else {
                    this.$axios( {
                        method: 'post',
                        url: 'Index/editdizhia',
                        data: {
                            uid: this.uid,
                            id: this.choosedId
                        }
                    } ).then( res => {
                        this.defaultAddr = res.data
                    } ).catch( error => {
                    } );
                }
            },
            showAddr() {
                this.$router.push('/chooseAddr')
            }
        },
    }
</script>

<style scoped>
    .container {
        padding: 0;
        background-image: url("../../../static/images/background.jpg");
        background-size: 100% 100%;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
    }

    .container >>> .mint-header {
        background-color: #ffa7539c;
    }
    .address-div {
        margin: 1vh;
        padding: 2vh;
        border-radius: 20px;
        color: #fff;
        font-weight: 500;

    }

    .address-arrow {
        flex-shrink: 0;
        line-height: 1.5em;
    }

    .address-info {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
    }

    .product-info {
        background-color: #fff;
        margin: 1vh;
        padding: 2vh;
        border-radius: 20px;
    }



    .userinfo-form {
        border-radius: 20px;
        padding: 1vh;
        margin: 1.5vh;
        display: flex;
        flex-direction: column;
        background-color: #fff;
        font-size: 28px;
    }

    .section {
        display: flex;
        flex-direction: row;
        padding: 0 30px;
        height: 100px;
        line-height: 100px;
        border-bottom: #F0F0F2 1px solid;
        background-color: #fff;
    }

    .section:last-child {
        border-bottom: none;
    }

    .section span {
        width: 30%;
        font-weight: 800;
    }

    .section input {
        width: 70%;
        padding-left: 30px;
        height: 80px;
        line-height: 80px;
        text-align: right;
    }

    .phone-section input {
        width: 220px;
    }

    .error-icon {
        margin-top: 23px;
    }

    .error .error-icon {
        display: block;
    }

    .error span {
        color: #F43530;
    }

    .error-info {
        height: 50px;
        margin-top: 10px;
        line-height: 50px;
        padding-left: 60px;
        color: #F43530;
    }

    .footer-info {
        position: absolute;
        bottom: 0;
        height: 120px;
        width: 100%;
        background-color: rgba(0, 0, 0, 0.6);
        color: #fff;
        display: flex;
        flex-direction: row;
        justify-content: flex-end;
    }

    .footer-info span {
        margin-top: 15px;
        line-height: 70px;
        font-weight: 500;
    }

    .project-btn {
        position: relative;
        margin-top: 15px;
        margin-left: 30px;
        margin-right: 20px;
        width: 25%;
        background: linear-gradient(to top right, #ff982f, #ecb649);
        height: 70px;
        font-size: 24px;
        font-weight: 900;
        line-height: 70px;
        border-radius: 40px;
        color: #fff;
        border: 0;
        z-index: 99;
    }

    .project {
        display: flex;
        flex-direction: row;
        border-bottom: #F0F0F2 1px solid;
        padding: 20px 0;
        justify-content: space-between;
    }

    .project:last-child {
        border-bottom: none;
    }

    .project .project-cover {
        width: 168px;
        height: 168px;
        margin-right: 24px;
        flex-shrink: 0;
    }

    .project-info {
        display: flex;
        flex-direction: column;
        width:100%;

        position: relative;
    }

    .project-info .project-name {
        margin-bottom: 20px;
        font-size: 30px;
        font-weight: 800;
    }

    .project-detail {
        width:100%;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        line-height: 40px;
        position: absolute;
        bottom: 0;
    }
</style>
